package com.feather.tenia.adapter.data;

import com.feather.common.data.Column;
import com.feather.common.data.DataColumn;
import com.feather.common.data.DataItemType;

/**
 * @author flogyin
 */
public class String_DataColumn implements DataColumn, java.io.Serializable {
	private static final long	serialVersionUID	= 1L;

	private Column				column;
	private String				data;

	public String_DataColumn(Column column) {
		this.column = column;
	}

	@Override
	public DataItemType getItemType() {
		return DataItemType.DataColumnItem;
	}

	@Override
	public Column getColumn() {
		return this.column;
	}

	@Override
	public boolean asBoolean() {
		return getBoolean();
	}

	@Override
	public boolean getBoolean() {
		return (("true".equalsIgnoreCase(this.data)) || ("1".equals(this.data)));
	}

	@Override
	public void setBoolean(boolean value) {
		this.data = String.valueOf(value);
	}

	@Override
	public String asString() {
		return this.data != null ? this.data : "";
	}

	@Override
	public String getString() {
		return this.data;
	}

	@Override
	public void setString(String value) {
		this.data = value;
	}

	@Override
	public byte asByte() {
		return this.data != null ? getByte() : 0;
	}

	@Override
	public byte getByte() {
		return Byte.parseByte(this.data);
	}

	@Override
	public void setByte(byte value) {
		this.data = String.valueOf(value);
	}

	@Override
	public byte[] getBytes() {
		return this.data != null ? this.data.getBytes() : null;
	}

	@Override
	public void setBytes(byte[] value) {
		this.data = value != null ? new String(value) : null;
	}

	@Override
	public short asShort() {
		return this.data != null ? getShort() : 0;
	}

	@Override
	public short getShort() {
		return Short.parseShort(this.data);
	}

	@Override
	public void setShort(short value) {
		this.data = String.valueOf(value);
	}

	@Override
	public int asInt() {
		return this.data != null ? getInt() : 0;
	}

	@Override
	public int getInt() {
		return Integer.parseInt(this.data);
	}

	@Override
	public void setInt(int value) {
		this.data = String.valueOf(value);
	}

	@Override
	public float asFloat() {
		return this.data != null ? getFloat() : 0;
	}

	@Override
	public float getFloat() {
		return Float.parseFloat(this.data);
	}

	@Override
	public void setFloat(float value) {
		this.data = String.valueOf(value);
	}

	@Override
	public long asLong() {
		return this.data != null ? getLong() : 0;
	}

	@Override
	public long getLong() {
		return Long.parseLong(this.data);
	}

	@Override
	public void setLong(long value) {
		this.data = String.valueOf(value);
	}

	@Override
	public double asDouble() {
		return this.data != null ? getDouble() : 0;
	}

	@Override
	public double getDouble() {
		return Double.parseDouble(this.data);
	}

	@Override
	public void setDouble(double value) {
		this.data = String.valueOf(value);
	}

	@Override
	public Object getObject() {
		return this.data;
	}

	@Override
	public void setObject(Object value) {
		if (value == null || (value instanceof String))
			this.data = (String) value;
		else
			throw new RuntimeException("Not support.");
	}
}
